package com.jenings.shop.controller;

import com.jenings.shop.entity.Comment;
import com.jenings.shop.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = {"评论pl"})
@RestController
@RequestMapping("/plApi")
public class CommentController {
    @Autowired
    CommentService commentService;
    //评论接口
    //查询全部评论
    @ApiOperation(value = "查询全部评论信息")
    @RequestMapping(value = "/selectAll", method = RequestMethod.POST)
    public List<Comment> selectAll(){
        List<Comment> commentList = commentService.selectAll();
        return commentList;
    }
    //查询部分评论，模糊查询
    @ApiOperation(value = "查询部分评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "plname", value = "评论内容", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/selectSome",method = RequestMethod.POST)
    public List<Comment> selectSome(@RequestParam(value = "plname") String plname){
        List<Comment> commentList = commentService.selectSome(plname);
        return commentList;
    }
    //查询指定评论
    @ApiOperation(value = "查询具体评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "plname", value = "评论内容", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/selectByte", method = RequestMethod.POST)
    public Comment selectByte(@RequestParam(value = "plname") String plname){
        Comment comment = commentService.selectByte(plname);
        return comment;
    }
    //添加评论
    @ApiOperation(value = "添加评论")
    @RequestMapping(value = "/addByte", method = RequestMethod.POST, produces = "application/json")
    public boolean addByte(@RequestBody Comment comment){
        return commentService.addByte(comment);
    }
    //删除评论
    @ApiOperation(value = "删除评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "plid", value = "评论id", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/delByte", method = RequestMethod.POST)
    public boolean delByte(@RequestParam(value = "plid") Integer plid){
        return commentService.delByte(plid);
    }
}
